package cn.schoolwow.quickdao.module.database.ddl.action.flow.table.common;

import cn.schoolwow.quickdao.domain.QuickDAOConfig;
import cn.schoolwow.quickdao.domain.entity.Entity;
import cn.schoolwow.quickdao.module.database.parent.flow.executor.ExecuteUpdateConnectionFlow;
import cn.schoolwow.quickflow.domain.FlowContext;
import cn.schoolwow.quickflow.flow.BusinessFlow;

public class ExecuteCreateTableFlow implements BusinessFlow {
    @Override
    public void executeBusinessFlow(FlowContext flowContext) throws Exception {
        QuickDAOConfig quickDAOConfig = flowContext.checkInstanceData(QuickDAOConfig.class);
        Entity entity = flowContext.checkData("entity", Entity.class);
        StringBuilder sqlBuilder = flowContext.checkData("sqlBuilder", StringBuilder.class);

        flowContext.startFlow(new ExecuteUpdateConnectionFlow())
                .putTemporaryData("name", "创建表")
                .putTemporaryData("sql", sqlBuilder.toString())
                .execute();
        //缓存表信息
        quickDAOConfig.databaseContext.databaseTableCache.put(entity.tableName, entity);
    }

    @Override
    public String name() {
        return "创建表";
    }
}
